package com.demo.装饰器;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName LoginSsoDecorator
 * @Author bsy
 * @Description 继承实现 功能拓展
 * @Date 2023/1/15 22:02
 * @Version 1.0
 */
public class LoginSsoDecorator extends SsoInterceptor{

    private static Map<String, String> authMap = new ConcurrentHashMap<String, String>();
    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }

    @Override
    public boolean preHandle(String request, String response, Object
            handler) {
        // 模拟获取cookie
        String ticket = request.substring(1, 8);
        // 模拟校验
        boolean success = ticket.equals("success");
        if (!success) return false;
        String userId = request.substring(9);
        String method = authMap.get(userId);
        // 模拟⽅法校验
        return "queryUserInfo".equals(method);
    }

}
